package com.jee.ssm.modules.evaluateUser.app;

import com.jee.ssm.common.utils.UUIDFactory;
import com.jee.ssm.model.EvaluateUser;
import com.jee.ssm.model.json.Tip;
import com.jee.ssm.modules.evaluateUser.services.EvaluateUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
* 评价管理 客户端 Controller
* @author GaoXiang
* @version 1.0
*/
@Controller
@RequestMapping("/app/evaluateUser")
public class AppEvaluateUserController {


    @RequestMapping(value="/saveUserFeedBackInfo")
    @ResponseBody
    public Tip saveUserFeedBackInfo(HttpServletRequest request,String workersId,String workersName){

        EvaluateUser evaluateUser = new EvaluateUser();
        String ratingType = request.getParameter("ratingType");
        int type = Integer.valueOf(ratingType);//评价类型
        if(type == 1){
            //反馈信息
            String feedBackInfo = request.getParameter("feedbackInfo");
            if(feedBackInfo != null && !feedBackInfo.equals("undefined")){
                evaluateUser.setFeedbackInfo(feedBackInfo);
            }
        }else if(type == 0){
            String userName = request.getParameter("userName");
            String userPhone = request.getParameter("userPhone");
            String resumeReason = request.getParameter("resumeReason");
            if(userName == null || userName.equals("undefined") || userName.trim().equals("")) return new Tip(1,"请输入您的姓名");
            if(userPhone == null || userPhone.equals("undefined") || userPhone.trim().equals("")) return new Tip(1,"请输入您的联系方式");
            if(resumeReason == null || resumeReason.equals("undefined") || resumeReason.trim().equals("")) return new Tip(1,"请简述您的反馈事项");
            evaluateUser.setUserName(userName);
            evaluateUser.setUserPhone(userPhone);
            evaluateUser.setResumeReason(resumeReason);
        }
        evaluateUser.setId(UUIDFactory.getStringId());
        evaluateUser.setCreateTime(new Date());
        evaluateUser.setRatingType(type);
        evaluateUser.setWorkersId(workersId);
        evaluateUser.setWorkersName(workersName);
        try {
            evaluateUserService.insert(evaluateUser);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Tip("保存成功");
    }

    /**
     * 描述： 评价成功页面
     * 创建时间：2020/10/13  YanZengBao
     * 修改时间：2020/10/13  YanZengBao 加注释
     * 修改时间：
     */
    @RequestMapping(value = "/successIndex")
    public String successIndex(){
        return "front/success";

    }





    //---------------------------- property -------------------------------

    @Resource
    private EvaluateUserService evaluateUserService;

}
